<template>
	<view class="socverifydrive" v-if="showPage" :style="'padding-bottom:'+ pageSafeArea +'rpx;'">
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">姓名</view>
			<view class="ml-10">{{info.name}}</view>
		</view>
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">电话</view>
			<view class="ml-10">{{info.mobile}}</view>
		</view>
		<view class="groupmanage_input_box box_bg" v-if="info.channel=='zh'">
			<view class="mr-5 label">粉丝嘉年华现场试乘预约</view>
			<view class="ml-10">{{info.project_name}}</view>
		</view>
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">试驾车型</view>
			<view class="ml-10">{{info.drive_car_series}}</view>
		</view>
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">试驾经销商</view>
			<view class="ml-10">{{info.company_info}}</view>
		</view>
		<view class="groupmanage_input_box box_bg">
			<view class="mr-5 label">预约时间</view>
			<view class="ml-10">{{info.create_time}}</view>
		</view>
		<view class="mt-50">
			<view v-if="info.sign_status==0" class="next_step_btn" @click="submitDriveVerify">确认核销</view>
			<view v-if="info.sign_status==1" class="next_step_btn_def">已核销</view>
			<view v-if="info.sign_status==2" class="next_step_btn_def">已取消</view>
		</view>
	</view>
</template>

<script>
	import {
		getDriveVerifyInfo,
		submitDriveVerify
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				id: '',
				info: '',
				isSubmit: true,
				showPage: false,
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
				safeBottom: uni.getSystemInfoSync().safeAreaInsets.bottom > 0 ? true : false,
				pageSafeArea: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets
					.bottom + 350 : 350,
				bottomSafeArea: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets
					.bottom : 15
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
			if (uni.getStorageSync('onload')) {
				this.getDriveVerifyInfo()
				uni.removeStorage({
					key: 'onload'
				})
			}
		},
		onLoad(options) {
			console.log(options)
			var scene = decodeURIComponent(options.scene)
			var list = scene.split('_');
			console.log(list)
			this.id = list[0]
			if (uni.getStorageSync('access_token')) {
				this.getDriveVerifyInfo()
			}
			var params = {
				event_code: '试驾核销',
				path: 'pages/testdrive/testdriveverify',
				event_id: this.id,
				title: '',
				source_page: '打开页面',
				value: '',
			}
			app.BurialPoint(params)
		},
		methods: {
			getDriveVerifyInfo() {
				getDriveVerifyInfo({
					id: this.id,
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
						this.showPage = true
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			submitDriveVerify() {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					uni.showModal({
						content: '确认核销吗？',
						confirmColor: '#00A0DC',
						confirmText: "确认",
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								submitDriveVerify({
									id: that.id,
								}).then(res => {
									if (res.state == 1) {
										that.getDriveVerifyInfo()
										that.isSubmit = true
										uni.showToast({
											title: '成功',
											mask: true,
											icon: 'success',
											duration: 1500
										})
										var params = {
											event_code: '试驾核销',
											path: 'pages/testdrive/testdriveverify',
											event_id: that.id,
											title: '',
											source_page: '试驾核销-确认完成',
											value: '',
										}
										app.BurialPoint(params)
									} else {
										uni.showToast({
											title: res.error[0],
											mask: true,
											icon: 'none',
											duration: 1500
										})
									}
								})

							} else if (res.cancel) {
								console.log('用户点击取消');
								that.isSubmit = true
							}
						}
					});
				}
			},
		},
	}
</script>

<style lang="scss">
	.socverifydrive {
		padding: 30rpx 70rpx;

		.groupmanage_input_box {
			min-height: 80rpx;
			font-size: 26rpx;
			margin-top: 20rpx;
			padding: 0 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-radius: 4px;
			background-color: #F7F7F7;
			border: 2rpx solid #F7F7F7;

			.label {
				color: #999;
				font-size: 26rpx;
			}
		}

		.projects_cell {
			margin-top: 40rpx;
			display: flex;
			align-items: center;
		}

		.projects_cell:first-child {
			margin-top: 20rpx;
		}

		.projects_btn {
			min-width: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			font-size: 24rpx;
			padding: 5rpx 10rpx;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}

		.projects_btn_def {
			min-width: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			font-size: 24rpx;
			padding: 5rpx 10rpx;
			border-radius: 8rpx;
			background-color: #949494;
		}

		.travel_img_box {
			width: 100%;
			height: 45vw;
			text-align: center;
			margin-top: 20rpx;
			border-radius: 8rpx;

			.travel_img {
				width: 100%;
				height: 45vw;
				border-radius: 8rpx;
			}
		}

		.next_step_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 25rpx 0;
			margin: 60rpx 0;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}

		.next_step_btn_def {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 25rpx 0;
			margin: 40rpx 0;
			border-radius: 8rpx;
			background-color: #E9E9E9;
		}

		.bottom_block_fixed {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 1;
			padding-left: 70rpx;
			padding-right: 70rpx;
			background-color: #ffffff;
		}
	}
</style>